<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ASIMS</title>
<link href="../CSS/style.css" rel="stylesheet" type="text/css" />

<script language="JavaScript">
function deleteAll()
{
	var checkboxSecondAll=document.getElementById('checkboxSecondAll');
	var checksecond=document.getElementsByName('checkboxsecond');
	var len=checksecond.length;
	for(var i=0;i<len;i++)
	{
			checksecond[i].checked=checkboxSecondAll.checked;
		
	   
	}

}
function addAll()
{
	var checkboxfirstAll=document.getElementById('checkboxfirstAll');
	//alert(checkboxfirstAll.checked);
	var checkfirst=document.getElementsByName('checkboxfirst');
	var len=checkfirst.length;
	for(var i=0;i<len;i++)
	{
	//checkfirst[i].checked=true;
		if(checkfirst[i].disabled===false){
			checkfirst[i].checked=checkboxfirstAll.checked;
			
		}
	   
	}

}
function addP(){
	var add=document.getElementById('permis').value;
	var checkfirst=document.getElementsByName('checkboxfirst');
	var len=checkfirst.length;
//	var first=true;
	for(var i=0;i<len;i++)
	{
	//checkfirst[i].checked=true;
		if(checkfirst[i].checked===true){
	//	if(first===false)
	    if(add!=="")
		  add+="@";
		// first=false;		
			add+=checkfirst[i].value;
			
		}
	   
	}
	var tb1=document.getElementById("tb1");
	for(i=1;i<tb1.rows.length-1;i++)
	{
		tb1.rows[i].deleteCell(1);
	}
	document.getElementById('checkboxfirstAll').checked=false;
	document.getElementById('permis').value=add.replace("@@","@");
	init();
}
function deleteP(){
    var undelete="";
	var checksecond=document.getElementsByName('checkboxsecond');
	var first=true;
	var len=checksecond.length;
	for(var i=0;i<len;i++)
	{
	//checkfirst[i].checked=true;
	   
		if(checksecond[i].checked!==true){
		if(first!==true)
	      undelete+="@";
	      first=false;
			undelete+=checksecond[i].value;
			
		}
	   
	}
	var tb1=document.getElementById("tb1");
	for(i=1;i<tb1.rows.length-1;i++)
	{
		tb1.rows[i].deleteCell(1);
	}
	document.getElementById('checkboxSecondAll').checked=false;
	document.getElementById('permis').value=undelete;
	init();
	
}
function init(){

var permissions=document.getElementById('permis').value.replace("@@","@");
//alert("cs："+permissions);
	var strs= new Array(); 
	strs=permissions.split("@");
	for(i=1;i<10;i++)
	{
	 var trs=document.getElementById("tr"+i);
	 if(i<=strs.length&&""!==strs[i-1])
	 {
	 	var   td   =   document.createElement( "<td class='secondtd'>");  
	    var   chk   =   document.createElement( "<input type='checkbox' name='checkboxsecond' value='"+strs[i-1]+"'/>"); 
	  
   		td.appendChild(chk);
   		trs.appendChild(td);
   		td.appendChild(document.createTextNode (strs[i-1])); 
   		  		
	 }
	 else
	 {
	     var   chk   =   document.createElement( "<td class='secondtd'>&nbsp;</td>"); 
   
   		 trs.appendChild(chk); 
	 }
	 
	}
	var checkfirst=document.getElementsByName('checkboxfirst');
	for(var i=0;i<checkfirst.length;i++)
	{
		if(permissions.indexOf(checkfirst[i].value)>=0){
		checkfirst[i].disabled=true;
		checkfirst[i].checked=false;
		}
		else
		checkfirst[i].disabled=false;
	}
}
function save()
{
//alert("save");
	roleTable.action="setPermissionForRole.action";
	roleTable.submit();
}
</script>
</head>

<body onload="init()">
	<div id="wrap">
		<div id="header">
			<h1 id="sitename"><a href="#">ASIMS</a></h1>
			<div id="nav">
				<div id="titleblock">
					<div id="subject">机场静态信息管理系统</div>
					<div id="spirit"><a href="#"><%= session.getAttribute("username") %>  已登录</a> | <a href ="javascript:window.location.href='queryUserForIndex.action'">个人信息维护</a> | <a href="../login/login.jsp" target="_parent">注销</a></div>
				 </div>
				<div id="topmenu">
					<ul>
						<li><a href="../login/index.jsp">首页</a></li>
						<li class="active"><a href="../rolemanage/user_manag.jsp">用户和角色管理</a></li>
						<li><a href="../airline_manage/airline_manag_InAr.jsp">航班信息管理</a></li>
						<li><a href="../facilities_manag/facilities_manag.jsp">机场设施管理</a></li>
						<li><a href="../news/news_view_intr.jsp">新闻中心</a></li>
					</ul>
				</div>
			</div>
			<div class="clear"></div>
			<div id="breadcrumb">网站路径：<a href="../login/index.jsp">首页</a> &raquo; <a href="#"  class="active">用户和角色管理</a></div>
		</div>
		
		<div id="content">
			<div id="right">
			   <div class="post">
					<h2><a href="">权限分配</a></h2>
						<form name="roleTable" method="post" enctype="multipart/form-data">
							<div class="contactform">
								<p class="first">
									<label for="rolename">角色名称：</label>
									<s:hidden name="role.roleId" value="%{#session.updateRole.roleId}"></s:hidden>
									<s:textfield name="role.rolename" value="%{#session.updateRole.rolename}"></s:textfield>
								<s:hidden id="permis" name="rolepermission.permissions" value="%{#session.rolePermissions}"/>
								</p>
								<p>
									<label for="rolename">描　　述：</label>
									<s:textarea name="role.rolespecification" value="%{#session.updateRole.rolespecification}" cols="400" rows="10" cssStyle="height:150px;width:400px" ></s:textarea>
									</p>
							</div>
						</form>
						<table id = "tb1" cellspacing="0" cellpadding="0">
							<tr>
							  <th scope="col"><strong>可分配权限</strong></th>
							  <th scope="col" class="secondth"><strong>已分配权限</strong></th>
							</tr>
							<tr id="tr1">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="用户管理" >
							  用户管理</td>
							 
							<tr id="tr2">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="角色、权限管理" >
							  角色、权限管理</td>
							  
							 <tr id="tr3">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="航班信息查询" >
							  航班信息查询</td>
							 
							</tr>
							<tr id="tr4">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value=" 航班信息管理（新增、删除、修改）">
								  航班信息管理（新增、删除、修改）</td>
							  
							</tr>
							<tr id="tr5">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="机场设施信息查询" >
									机场设施信息查询</td>
							 
							</tr>
							<tr id="tr6">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="机场设施信息管理（新增、删除、修改）">
									机场设施信息管理（新增、删除、修改）</td>
							 
							</tr>
							<tr id="tr7">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="新闻浏览">
									新闻浏览</td>
							 
							</tr>
							<tr id="tr8">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="新闻订阅">
									新闻订阅</td>
							  
							</tr>
								<tr id="tr9">
							  <td class="firsttd">　<input type="checkbox" name="checkboxfirst" value="新闻发布">
									新闻发布</td>
							  
							</tr>
								<tr>
							  <td class="firsttd">　<input type="checkbox" id="checkboxfirstAll" value="checkbox" onClick="addAll()">
							  全选　<button type="submit" name="add" onClick="addP()">
									添加选中权限
								</button>
							</td>
							  <td class="secondtd">　<input type="checkbox" id="checkboxSecondAll" value="checkbox" onClick="deleteAll()">
							  全选　
								<button type="submit" name="del" onClick="deleteP()">
									删除选中权限
								</button></td>
							</tr>
						  </table>
				</div>
				<div class="buttons">
						<div class="butarea2"></div>
						<button type="submit" name="add" onClick="save()" >
							<img src="../images/import16.png" alt="" /> 
							保存
						</button>
						<button type="reset" name="cancel" onClick="javascript:window.location.href='role_manag.jsp'">
							<img src="../images/cancel16.png" alt=""/> 
							取消
						</button>
				　</div>
			</div>
	
			<div id="sidebar">
				<div id="sidebartop"></div>
					<h2>用户管理和角色管理</h2>
						<ul>
						  <li><a href="queryAllUser.action">用户管理</a></li>
						  <li class="active"><a href="queryRoleAuto.action">角色管理</a></li>
						</ul>
			</div>
			<div class="clear"></div>
			<div id="bottom">
				<p><img src="../images/copyright.jpg" /></p>
				<p><a href="">隐私权</a> | <a href="">&copy;版权</a> | <a href="">法律声明</a> | <a href="">电子邮件：admin@163.com</a>
			</div>
		</div>
		
		<div id="footer">
			<div id="credits">
				ASIMS Power by IBM
			</div>
		</div>
	</div>

</body>
</html>